﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/AdminSite.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@Import Namespace="MensUnoShop.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	List
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%
    List<UHotKey> searchkeylist = ViewData["searchkeylist"] as List<UHotKey>;
%>
     <div id="main-content" class="hastable" style="width:1150px;">
		<div class="title title-spacing">
		  <h2>熱門關鍵字管理</h2>
		</div>
        <div style="float:left;margin-top:37px;">
            
            <table cellspacing="0" style="width:400px;">
            <thead>
		    <tr>
			    <td style="width:40px" class="center">序號</td>
			    <td style="width:40px" class="center">關鍵字</td>
			    <td style="width:40px" class="center">搜尋次數</td>
			    <td style="width:40px" class="center">操作</td>
		    </tr>     
            </thead>   
            <tbody>
            <%int i = 1; foreach (var hk in searchkeylist)
              {
                   %>
		    <tr>
			    <td style="width:40px" class="center"><%:i %></td>
			    <td style="width:40px" class="center"><%:hk.HTkey %></td>
			    <td style="width:40px" class="center"><%:hk.HTcount %></td>
			    <td style="width:40px" class="center"><input type="button" value="加入熱門關鍵字列表" onclick="addHotKey('<%:hk.HTkey %>');"/></td>
		    </tr> 
            <%
                i++;
              } %>       
            </tbody>
        </table>
    </div>
    <div style="float:left;margin-left:120px;">
        新增熱門關鍵字：<input type="text" id="mkeyword" /><input type="button" value="手動新增" onclick="addHotKey($('#mkeyword').val());">
        <table cellspacing="0" style="width:600px;margin-top:10px;" id="hotkeylist">
            <thead>
		    <tr>
			    <td style="width:20px" class="center">序號</td>
			    <td style="width:40px" class="center">熱門關鍵字</td>
			    <td style="width:100px" class="center">色碼</td>
			    <td style="width:40px" class="center">刪除</td>
		    </tr>     
            </thead>   
            <tbody>
            </tbody>
        </table>
    </div>
    <div id="bk" style="width:100%;height:1000px;position:absolute; top:0px; left:0px;background-color:Black;z-index:999999;filter:alpha(opacity=50);-moz-opacity:0.5;opacity: 0.5;"></div>
    <%
        string colorlist = ViewData["colorlist"].ToString();
         %>
    <script type="text/javascript">
        var colorlist = '<%=colorlist %>'.split(',');
        $("#bk").show();
        $.ajax({
            type: "GET",
            traditional: true,
            url: "/Admin/KeywordSetup/api_getkeywordlist",
            dataType: "json",
            success: function (data) {
                if (data.code == "200") {
                    setTable(data);
                }
                else
                    alert(data.response);
                $("#bk").hide();
            }
        });

        function addHotKey(hkid) {
            $("#bk").show();
            var json = { keyword: hkid };
            $.ajax({
                type: "POST",
                traditional: true,
                url: "/Admin/KeywordSetup/api_addkeyword",
                data: json,
                dataType: "json",
                success: function (data) {
                    if (data.code == "200") {
                        setTable(data);
                    }
                    else
                        alert(data.response);
                    $("#bk").hide();
                }
            });
        }

        function delHotKey(hkid) {
            if (confirm('是否確定刪除?')) {
                $("#bk").show();
                var json = { keyword: hkid };
                $.ajax({
                    type: "POST",
                    traditional: true,
                    url: "/Admin/KeywordSetup/api_delkeyword",
                    data: json,
                    dataType: "json",
                    success: function (data) {
                        if (data.code == "200") {
                            setTable(data);
                        }
                        else
                            alert(data.response);
                        $("#bk").hide();
                    }
                });
            }
        }

        function chgHotKeyColor(hkid, colorid) {
            $("#bk").show();
            var json = { keyword: hkid, cid:colorid };
            $.ajax({
                type: "POST",
                traditional: true,
                url: "/Admin/KeywordSetup/api_setkeywordcolor",
                data: json,
                dataType: "json",
                success: function (data) {
                    if (data.code == "200") {
                        setTable(data);
                    }
                    else
                        alert(data.response);
                    $("#bk").hide();
                }
            });
        }

        function setTable(data) {
            var tb = $("#hotkeylist tbody");
            tb.empty();
            for (var i = 0; i < data.keyword.length; i++) {
                var tt = '<tr>';
                tt += '<td style="width:20px" class="center">' + (i + 1) + '</td><td style="width:40px" class="center">' + data.keyword[i] + '</td>';
                tt += '<td style="width:40px" class="center">';
                var dd = '';
                for (var j = 0; j < colorlist.length; j++) {
                    dd += '<input type="radio" name="color_' + i + '" value="' + j + '" onclick=\'chgHotKeyColor("' + data.keyword[i] + '", ' + j + ');\' /> ' + '<span style="color:' + colorlist[j] + ';font-sixe:12pt">ெ</span>&nbsp;';
                }

                tt += dd + '</td>';
                tt += '<td style="width:40px" class="center"><input type="button" value="移除" onclick=\'delHotKey("' + data.keyword[i] + '")\'/></td></tr>';
                tb.append(tt);
                $('input:radio[name="color_' + i + '"][value=' + data.color[i] + ']').attr("checked", true);
            }
        }

    </script>
</asp:Content>
